using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace ClickSocial
{
    public class Global : System.Web.HttpApplication
    {
        public static class RolesApp
        {
            public static string Host = "Host", Fotografo = "Fotografo", User = "User", UserEvent = "UserEvent";
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();

            DirectoryInfo BaseDir = new DirectoryInfo(Server.MapPath("~/App_Data/Archivos"));

            if (!BaseDir.Exists)
            {
                Directory.CreateDirectory(Server.MapPath("~/App_Data/Archivos"));
            }

            Application["BaseDir"] = Server.MapPath("~/App_Data/Archivos");

            DirectoryInfo BaseThumbnails = new DirectoryInfo(Server.MapPath("~/App_Data/Thumbnails"));

            if (!BaseThumbnails.Exists)
            {
                Directory.CreateDirectory(Server.MapPath("~/App_Data/Thumbnails"));
            }

            Application["BaseThumbnails"] = Server.MapPath("~/App_Data/Thumbnails");


            if (!Roles.RoleExists("Host"))
                Roles.CreateRole("Host");
            
            if (!Roles.RoleExists("Fotografo"))
                Roles.CreateRole("Fotografo");
            
            if (!Roles.RoleExists("User"))
                Roles.CreateRole("User");
            
            if (!Roles.RoleExists("UserEvent"))
                Roles.CreateRole("UserEvent");

            MembershipUser user = Membership.GetUser("host");

            if (user == null)
            {
                MembershipCreateStatus status;

                user = Membership.CreateUser("host", "host", "host@clicksocial.com", "Nombre del host", "host", true, out status);

                if (status == MembershipCreateStatus.Success)
                    Roles.AddUserToRole(user.UserName, "Host");

                //Directory.CreateDirectory(Server.MapPath("~/App_Data/Archivos/Mike"));
            }          

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}